package com.ruoyi.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.demo.ClassInfo;
import com.ruoyi.demo.StudentInfo;
import com.ruoyi.mapper.StudentMapper;
import com.ruoyi.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/classinfo")
public class ClassController {

//    @Autowired
//    private ClassService service;

//    @GetMapping("/list")
//    public List<ClassInfo> list() {
//        List<ClassInfo> list = service.list();
//        return list;
//    }
//    @GetMapping("/getListById")
//    public List<ClassInfo> getListById(ClassInfo info){
//        List<ClassInfo> list = service.getListById(info);
//        return AjaxResult.success();
//    }
//
//}


//
    @Resource
    private StudentMapper studentMapper;

    @GetMapping("/list")
    public List<StudentInfo> list1() {
        List<StudentInfo> list = studentMapper.list();
        return list;
    }

    @GetMapping("/getlist")
    public AjaxResult getList(@RequestParam("age") String age,@RequestParam(value = "id",required = false)Integer id){
        List<StudentInfo> list = studentMapper.getList(age,id);
        return AjaxResult.success();
    }

    @DeleteMapping("delete")
    public AjaxResult delete(Integer id){
        studentMapper.delete(id);
        return AjaxResult.success();
    }



    @GetMapping("/by")
    public AjaxResult by(@RequestParam(name = "ids",required = true) Integer id){
        System.out.println(id);
        return AjaxResult.success();
    }


    @PostMapping("/in")
    public AjaxResult create(@RequestBody StudentInfo studentInfo){
        System.out.println(studentInfo);
        studentMapper.create(studentInfo);
        return  AjaxResult.success();
    }

    @DeleteMapping("deleteIds")
    public AjaxResult deleteIds(@RequestBody Integer[] id) {
        for (int i = 0; i < id.length; i++) {
            System.out.println(id[i]);
        }
            studentMapper.deleteIds(id);
            return AjaxResult.success();
        }

    @GetMapping("/text/{id}")
    public  AjaxResult text(@PathVariable String id){
        System.out.println(id);
        return  AjaxResult.success();
    }
}

